home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / GlobWiz.frm < prev    next >
Text File  |  1997-06-14  |  26KB  |  862 lines

  1. VERSION 5.00
  2. Begin VB.Form FGlobalWizard 
  3.    Caption         =   "Global Wizard"
  4.    ClientHeight    =   6720
  5.    ClientLeft      =   780
  6.    ClientTop       =   2190
  7.    ClientWidth     =   8280
  8.    Icon            =   "GlobWiz.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   6720
  11.    ScaleWidth      =   8280
  12.    Begin VB.CheckBox chkDeclView 
  13.       Caption         =   "View"
  14.       Enabled         =   0   'False
  15.       Height          =   285
  16.       Left            =   7275
  17.       TabIndex        =   23
  18.       Top             =   2490
  19.       Width           =   780
  20.    End
  21.    Begin VB.TextBox txtSrcModName 
  22.       Enabled         =   0   'False
  23.       Height          =   285
  24.       Left            =   1335
  25.       TabIndex        =   21
  26.       Top             =   1845
  27.       Width           =   1788
  28.    End
  29.    Begin VB.TextBox txtSrcModType 
  30.       Enabled         =   0   'False
  31.       Height          =   285
  32.       Left            =   1335
  33.       TabIndex        =   18
  34.       Top             =   2145
  35.       Width           =   1788
  36.    End
  37.    Begin VB.TextBox txtSrcFileName 
  38.       Enabled         =   0   'False
  39.       Height          =   285
  40.       Left            =   1335
  41.       TabIndex        =   17
  42.       Top             =   1530
  43.       Width           =   1788
  44.    End
  45.    Begin VB.TextBox txtDeclFileName 
  46.       Enabled         =   0   'False
  47.       Height          =   285
  48.       Left            =   5415
  49.       TabIndex        =   13
  50.       Top             =   2445
  51.       Width           =   1788
  52.    End
  53.    Begin VB.TextBox txtDstModType 
  54.       Enabled         =   0   'False
  55.       Height          =   285
  56.       Left            =   5415
  57.       TabIndex        =   12
  58.       Top             =   2145
  59.       Width           =   1788
  60.    End
  61.    Begin VB.CheckBox chkDelegate 
  62.       Caption         =   "Delegate"
  63.       Height          =   204
  64.       Left            =   5415
  65.       TabIndex        =   11
  66.       Top             =   1275
  67.       Width           =   1488
  68.    End
  69.    Begin VB.TextBox txtDstFileName 
  70.       Height          =   285
  71.       Left            =   5415
  72.       TabIndex        =   10
  73.       Top             =   1530
  74.       Width           =   1788
  75.    End
  76.    Begin VB.TextBox txtDstModName 
  77.       Height          =   285
  78.       Left            =   5415
  79.       TabIndex        =   9
  80.       Top             =   1845
  81.       Width           =   1788
  82.    End
  83.    Begin VB.ComboBox cboType 
  84.       Height          =   315
  85.       ItemData        =   "GlobWiz.frx":0CFA
  86.       Left            =   2520
  87.       List            =   "GlobWiz.frx":0D07
  88.       TabIndex        =   7
  89.       Text            =   "Both (*.bas and *.cls)"
  90.       Top             =   108
  91.       Width           =   2310
  92.    End
  93.    Begin VB.DriveListBox drvCur 
  94.       Height          =   315
  95.       Left            =   108
  96.       TabIndex        =   4
  97.       Top             =   108
  98.       Width           =   2310
  99.    End
  100.    Begin VB.DirListBox dirCur 
  101.       Height          =   765
  102.       Left            =   108
  103.       TabIndex        =   3
  104.       Top             =   495
  105.       Width           =   2310
  106.    End
  107.    Begin VB.FileListBox fileCur 
  108.       Height          =   675
  109.       Left            =   2505
  110.       Pattern         =   "*.cls;*.bas"
  111.       TabIndex        =   2
  112.       Top             =   480
  113.       Width           =   2310
  114.    End
  115.    Begin VB.CommandButton cmdClose 
  116.       Caption         =   "Close"
  117.       Height          =   375
  118.       Left            =   5880
  119.       TabIndex        =   1
  120.       Top             =   600
  121.       Width           =   2256
  122.    End
  123.    Begin VB.CommandButton cmdCreate 
  124.       Caption         =   "Save File"
  125.       Height          =   375
  126.       Left            =   5892
  127.       TabIndex        =   0
  128.       Top             =   120
  129.       Width           =   2268
  130.    End
  131.    Begin VB.TextBox txtSrc 
  132.       BeginProperty Font 
  133.          Name            =   "Courier New"
  134.          Size            =   9
  135.          Charset         =   0
  136.          Weight          =   400
  137.          Underline       =   0   'False
  138.          Italic          =   0   'False
  139.          Strikethrough   =   0   'False
  140.       EndProperty
  141.       Height          =   3696
  142.       Left            =   120
  143.       Locked          =   -1  'True
  144.       MultiLine       =   -1  'True
  145.       ScrollBars      =   3  'Both
  146.       TabIndex        =   16
  147.       Top             =   2928
  148.       Width           =   3972
  149.    End
  150.    Begin VB.TextBox txtDst 
  151.       BeginProperty Font 
  152.          Name            =   "Courier New"
  153.          Size            =   9
  154.          Charset         =   0
  155.          Weight          =   400
  156.          Underline       =   0   'False
  157.          Italic          =   0   'False
  158.          Strikethrough   =   0   'False
  159.       EndProperty
  160.       Height          =   3696
  161.       Left            =   4200
  162.       MultiLine       =   -1  'True
  163.       ScrollBars      =   3  'Both
  164.       TabIndex        =   5
  165.       Top             =   2928
  166.       Width           =   3972
  167.    End
  168.    Begin VB.TextBox txtDecl 
  169.       BeginProperty Font 
  170.          Name            =   "Courier New"
  171.          Size            =   9
  172.          Charset         =   0
  173.          Weight          =   400
  174.          Underline       =   0   'False
  175.          Italic          =   0   'False
  176.          Strikethrough   =   0   'False
  177.       EndProperty
  178.       Height          =   3696
  179.       Left            =   120
  180.       MultiLine       =   -1  'True
  181.       ScrollBars      =   3  'Both
  182.       TabIndex        =   24
  183.       Top             =   2928
  184.       Visible         =   0   'False
  185.       Width           =   8050
  186.    End
  187.    Begin VB.Label lbl 
  188.       Caption         =   "Module name:"
  189.       Height          =   255
  190.       Index           =   2
  191.       Left            =   120
  192.       TabIndex        =   22
  193.       Top             =   1860
  194.       Width           =   1095
  195.    End
  196.    Begin VB.Label lbl 
  197.       Caption         =   "Module type:"
  198.       Height          =   255
  199.       Index           =   3
  200.       Left            =   120
  201.       TabIndex        =   20
  202.       Top             =   2160
  203.       Width           =   1095
  204.    End
  205.    Begin VB.Label lbl 
  206.       Caption         =   "Source"
  207.       BeginProperty Font 
  208.          Name            =   "MS Sans Serif"
  209.          Size            =   9.75
  210.          Charset         =   0
  211.          Weight          =   700
  212.          Underline       =   0   'False
  213.          Italic          =   0   'False
  214.          Strikethrough   =   0   'False
  215.       EndProperty
  216.       Height          =   255
  217.       Index           =   0
  218.       Left            =   120
  219.       TabIndex        =   19
  220.       Top             =   1530
  221.       Width           =   855
  222.    End
  223.    Begin VB.Label lbl 
  224.       Caption         =   "Declarations:"
  225.       Height          =   255
  226.       Index           =   6
  227.       Left            =   4200
  228.       TabIndex        =   15
  229.       Top             =   2460
  230.       Width           =   1095
  231.    End
  232.    Begin VB.Label lbl 
  233.       Caption         =   "Module type:"
  234.       Height          =   255
  235.       Index           =   5
  236.       Left            =   4200
  237.       TabIndex        =   14
  238.       Top             =   2175
  239.       Width           =   1095
  240.    End
  241.    Begin VB.Label lbl 
  242.       Caption         =   "Module name:"
  243.       Height          =   255
  244.       Index           =   4
  245.       Left            =   4200
  246.       TabIndex        =   8
  247.       Top             =   1875
  248.       Width           =   1095
  249.    End
  250.    Begin VB.Label lbl 
  251.       Caption         =   "Target"
  252.       BeginProperty Font 
  253.          Name            =   "MS Sans Serif"
  254.          Size            =   9.75
  255.          Charset         =   0
  256.          Weight          =   700
  257.          Underline       =   0   'False
  258.          Italic          =   0   'False
  259.          Strikethrough   =   0   'False
  260.       EndProperty
  261.       Height          =   255
  262.       Index           =   1
  263.       Left            =   4200
  264.       TabIndex        =   6
  265.       Top             =   1530
  266.       Width           =   855
  267.    End
  268. End
  269. Attribute VB_Name = "FGlobalWizard"
  270. Attribute VB_GlobalNameSpace = False
  271. Attribute VB_Creatable = False
  272. Attribute VB_PredeclaredId = True
  273. Attribute VB_Exposed = False
  274. Option Explicit
  275.  
  276. Private sFileSrc As String
  277. Private sFileDst As String
  278.  
  279. Enum EFileType
  280.     eftBoth
  281.     eftStandard
  282.     eftClass
  283. End Enum
  284.  
  285. Enum EModuleType
  286.     emtStandard
  287.     emtClassPublic
  288.     emtClassGlobal
  289.     emtClassPrivate
  290.     emtInvalid
  291. End Enum
  292.  
  293. Private emtCur As EModuleType
  294. Private fDeclChanged As Boolean
  295.  
  296. Sub GetDecl()
  297.     sFileDst = NormalizePath(fileCur.Path)
  298.     sFileDst = sFileDst & txtDeclFileName
  299.     
  300.     If Not ExistFileDir(sFileDst) Then
  301.         Dim result As VbMsgBoxResult
  302.     
  303.         result = MsgBox(sFileDst & " doesn't exist. Create? ", vbYesNoCancel, "Global Wizard")
  304.         If result = vbYes Then
  305.             On Error GoTo CreateError
  306.             CreateDeclFile
  307.         Else
  308.             chkDeclView = vbUnchecked
  309.             Exit Sub
  310.         End If
  311.     End If
  312.  
  313.     On Error GoTo AccessError
  314.     ' Get text of file regardless
  315.     txtDecl = GetFileText(sFileDst)
  316.     fDeclChanged = False
  317.     Exit Sub
  318.     
  319. CreateError:
  320.     MsgBox Err.Description & sCrLf & sCrLf & _
  321.            "Unable to create file " & sFileDst, vbOKOnly + vbExclamation, "Global Wizard"
  322.     chkDeclView = vbUnchecked
  323.     Exit Sub
  324.     
  325. AccessError:
  326.     MsgBox Err.Description & sCrLf & sCrLf & _
  327.            "Unable to open file " & sFileDst, vbOKOnly + vbExclamation, "Global Wizard"
  328.     chkDeclView = vbUnchecked
  329. End Sub
  330.  
  331. Private Sub SaveDecl()
  332.     On Error GoTo SaveError
  333.     
  334.     fDeclChanged = False
  335.     SaveFileStr sFileDst, txtDecl
  336.     Exit Sub
  337.     
  338. SaveError:
  339.     MsgBox Err.Description & sCrLf & sCrLf & _
  340.            "Unable to save changes to global object declarations.", vbOKOnly + vbExclamation, "Global Wizard"
  341. End Sub
  342.  
  343. Private Sub cboType_Click()
  344.     Select Case cboType.ListIndex
  345.     Case eftBoth
  346.         fileCur.Pattern = "*.cls;*.bas"
  347.     Case eftStandard
  348.         fileCur.Pattern = "*.bas"
  349.     Case eftClass
  350.         fileCur.Pattern = "*.cls"
  351.     End Select
  352.     fileCur.Refresh
  353.     If fileCur.ListCount > 0 Then
  354.         fileCur.ListIndex = 0
  355.     Else
  356.         DisplayNothing
  357.     End If
  358. End Sub
  359.  
  360. Private Sub chkDeclView_Click()
  361.     On Error GoTo FileError
  362.     
  363.     ' Save changes to current declarations file
  364.     If fDeclChanged Then SaveDecl
  365.     ' Load new declarations file
  366.     If chkDeclView = vbChecked Then GetDecl
  367.     
  368.     ' Update the display
  369.     cmdCreate.Enabled = (chkDeclView = vbUnchecked)
  370.     chkDelegate.Enabled = (chkDeclView = vbUnchecked)
  371.     txtDstFileName.Enabled = (chkDeclView = vbUnchecked)
  372.     txtDstModName.Enabled = (chkDeclView = vbUnchecked)
  373.     txtSrc.Visible = (chkDeclView = vbUnchecked)
  374.     txtDst.Visible = (chkDeclView = vbUnchecked)
  375.     txtDecl.Visible = (chkDeclView = vbChecked)
  376.     Exit Sub
  377.     
  378. FileError:
  379.     MsgBox Err.Description & sCrLf & sCrLf & _
  380.            "Unable to open file " & sFileDst, vbOKOnly + vbExclamation, "Global Wizard"
  381.     chkDeclView = vbUnchecked
  382.     Resume Next
  383. End Sub
  384.  
  385. Private Sub chkDelegate_Click()
  386.     If chkDelegate Then
  387.         txtDeclFileName.Text = "N/A"
  388.         txtDeclFileName.Enabled = False
  389.         chkDeclView.Enabled = False
  390.     Else
  391.         txtDeclFileName.Text = "Objects.Bas"
  392.         txtDeclFileName.Enabled = True
  393.         chkDeclView.Enabled = True
  394.     End If
  395.     UpdateTargetFileDisplay
  396. End Sub
  397.  
  398. Private Sub cmdClose_Click()
  399.     Unload Me
  400. End Sub
  401.  
  402. Private Sub cmdCreate_Click()
  403.     On Error GoTo FileError
  404.     Dim sPath As String
  405.     
  406.     sPath = NormalizePath(fileCur.Path)
  407.     sFileDst = sPath & txtDstFileName
  408.     If ExistFile(sFileDst) Then
  409.         If CreateBackupFile = vbCancel Then Exit Sub
  410.     End If
  411.     SaveFileStr sFileDst, txtDst
  412.     
  413.     If (emtCur = emtStandard) And (chkDelegate = vbUnchecked) Then
  414.         sFileDst = sPath & txtDeclFileName
  415.         If Not ExistFile(sFileDst) Then CreateDeclFile
  416.         UpdateDeclFile
  417.     End If
  418.     Exit Sub
  419.     
  420. FileError:
  421.     MsgBox Err.Description & sCrLf & sCrLf & _
  422.            "Unable to create file " & sFileDst, vbOKOnly + vbExclamation, "Global Wizard"
  423. End Sub
  424.  
  425. Private Sub dirCur_Change()
  426.     fileCur.Path = dirCur.Path
  427.     If fileCur.ListCount > 0 Then
  428.         fileCur.ListIndex = 0
  429.     Else
  430.         DisplayNothing
  431.     End If
  432. End Sub
  433.  
  434. Private Sub drvCur_Change()
  435.     dirCur.Path = drvCur.Drive
  436. End Sub
  437.  
  438. Private Sub fileCur_Click()
  439.     sFileSrc = NormalizePath(fileCur.Path)
  440.     sFileSrc = sFileSrc & fileCur.filename
  441.     
  442.     Dim sModName As String
  443.     txtSrc = GetModuleInfo(sFileSrc, sModName)
  444.     txtSrcModName = sModName
  445.     txtSrcFileName = GetFileBaseExt(sFileSrc)
  446.     
  447.     Select Case emtCur
  448.     Case emtInvalid
  449.         DisplayInvalid
  450.     Case emtStandard
  451.         DisplayStandard
  452.     Case emtClassPublic
  453.         DisplayPublic
  454.     Case emtClassGlobal
  455.         DisplayGlobal
  456.     Case emtClassPrivate
  457.         DisplayPrivate
  458.     End Select
  459.     If emtCur <> emtInvalid Then
  460.         txtDstFileName.Enabled = True
  461.         cmdCreate.Enabled = True
  462.         UpdateTargetFileDisplay
  463.     End If
  464. End Sub
  465.  
  466. Private Sub Form_Load()
  467.     ChDir App.Path
  468.     If fileCur.ListCount > 0 Then
  469.         fileCur.ListIndex = 0
  470.     End If
  471. End Sub
  472.  
  473. Function GetModuleInfo(sFileSrc As String, sModName As String) As String
  474.     Dim s As String, iStart As Long, iEnd As Long, sTmp As String
  475.     Const sTargetName As String = "Attribute VB_Name = """
  476.     Const sTargetPublic As String = "VB_Exposed = "
  477.     Const sTargetGlobal As String = "Attribute VB_GlobalNameSpace = "
  478.     
  479.     On Error GoTo FailGetModuleInfo
  480.     ' Get text of file regardless
  481.     s = GetFileText(sFileSrc)
  482.     ' Find module name
  483.     iStart = InStr(s, sTargetName)
  484.     If iStart = 0 Then GoTo FailGetModuleInfo
  485.     iStart = iStart + Len(sTargetName)
  486.     iEnd = InStr(iStart, s, sQuote2)
  487.     If iEnd = 0 Then GoTo FailGetModuleInfo
  488.     sModName = Mid$(s, iStart, iEnd - iStart)
  489.     ' Find module type
  490.     If UCase$(GetFileExt(sFileSrc)) = ".BAS" Then
  491.         emtCur = emtStandard
  492.     Else
  493.         ' Find public attribute
  494.         iStart = InStr(s, sTargetPublic)
  495.         If iStart = 0 Then GoTo FailGetModuleInfo
  496.         iStart = iStart + Len(sTargetPublic)
  497.         sTmp = Mid$(s, iStart, 1)
  498.         Select Case sTmp
  499.         Case "F"
  500.             emtCur = emtClassPrivate
  501.         Case "T"
  502.             ' Find global attribute
  503.             iStart = InStr(s, sTargetGlobal)
  504.             If iStart = 0 Then GoTo FailGetModuleInfo
  505.             iStart = iStart + Len(sTargetGlobal)
  506.             sTmp = Mid$(s, iStart, 1)
  507.             Select Case sTmp
  508.             Case "F"
  509.                 emtCur = emtClassPublic
  510.             Case "T"
  511.                 emtCur = emtClassGlobal
  512.             Case Else
  513.                 GoTo FailGetModuleInfo
  514.             End Select
  515.         Case Else
  516.             GoTo FailGetModuleInfo
  517.         End Select
  518.     End If
  519.     GetModuleInfo = s
  520.     Exit Function
  521.     
  522. FailGetModuleInfo:
  523.     ' Any number of reasons why module might be invalid
  524.     emtCur = emtInvalid
  525.     GetModuleInfo = s
  526. End Function
  527.  
  528. Sub UpdateTargetFileDisplay()
  529.     HourGlass Me
  530.     
  531.     ' Select the appropriate filter and assign to any old object
  532.     Dim filterobj As Object
  533.     Select Case emtCur
  534.     Case emtStandard
  535.         If chkDelegate Then
  536.             ' Translates standard module to global class with delegation
  537.             Set filterobj = New CModGlobDelFilter
  538.         Else
  539.             ' Translates standard module to global class w/o delegation
  540.             Set filterobj = New CModGlobFilter
  541.         End If
  542.     Case emtClassPublic
  543.         ' Translates public class to private class
  544.         Set filterobj = New CPubPrivFilter
  545.     Case emtClassGlobal
  546.         ' Translates global class to standard module
  547.         Set filterobj = New CGlobModFilter
  548.     Case emtClassPrivate
  549.         ' Translates private class to public class
  550.         Set filterobj = New CPrivPubFilter
  551.     Case Else
  552.         txtDst = ""
  553.         Exit Sub
  554.     End Select
  555.     ' Setting name isn't performance sensitive, so do it late bound
  556.     filterobj.Name = txtDstModName
  557.     
  558.     ' Use early-bound variable for performance sensitive filter
  559.     Dim filter As IFilter
  560.     Set filter = filterobj
  561.     filter.Source = txtSrc
  562.     FilterText filter
  563.     txtDst = filter.Target
  564.     HourGlass Me
  565. End Sub
  566.  
  567. Private Sub txtDecl_Change()
  568.     fDeclChanged = True
  569. End Sub
  570.  
  571. Private Sub txtDeclFileName_KeyPress(KeyAscii As Integer)
  572.     If KeyAscii = 13 Then
  573.         KeyAscii = 0
  574.         ' Update the same as if we've lost focus
  575.         txtDeclFileName_LostFocus
  576.     End If
  577. End Sub
  578.  
  579. Private Sub txtDeclFileName_LostFocus()
  580.     Dim sExt As String, sPath As String
  581.     
  582.     If txtDeclFileName = sEmpty Then
  583.         txtDeclFileName = "Objects.Bas"
  584.     Else
  585.         sPath = NormalizePath(fileCur.Path)
  586.         sExt = GetFileExt(sPath & txtDeclFileName)
  587.         If sExt = sEmpty Then
  588.             txtDeclFileName = txtDeclFileName & ".Bas"
  589.         ElseIf UCase$(sExt) <> ".BAS" Then
  590.             MsgBox "Invalid filename", vbOKOnly + vbExclamation, "Global Wizard"
  591.             txtDeclFileName = "Objects.Bas"
  592.         End If
  593.     End If
  594.     If chkDeclView = vbChecked Then chkDeclView_Click
  595. End Sub
  596.  
  597. Private Sub txtDstFileName_KeyPress(KeyAscii As Integer)
  598.     If KeyAscii = 13 Then
  599.         KeyAscii = 0
  600.         ' Update the same as if we've lost focus
  601.         txtDstFileName_LostFocus
  602.     End If
  603. End Sub
  604.  
  605. Private Sub txtDstFileName_LostFocus()
  606.     Dim sExt As String, sPath As String
  607.     
  608.     If txtDstFileName <> sEmpty Then
  609.         sPath = NormalizePath(fileCur.Path)
  610.         sExt = GetFileExt(sPath & txtDstFileName)
  611.         ' If no extension, tack on the correct one
  612.         If sExt = sEmpty Then
  613.             sExt = IIf(emtCur = emtClassGlobal, ".Bas", ".Cls")
  614.             txtDstFileName = txtDstFileName & sExt
  615.             Exit Sub
  616.         Else
  617.             ' Normalize the extension
  618.             sExt = UCase$(sExt)
  619.             ' Check for a correct extension
  620.             If sExt = IIf(emtCur = emtClassGlobal, ".BAS", ".CLS") Then
  621.                 Exit Sub
  622.             Else
  623.                 MsgBox "Invalid extension", vbOKOnly + vbExclamation, "Global Wizard"
  624.             End If
  625.         End If
  626.     End If
  627.     ' Target filename invalid. Display the default
  628.     txtDstFileName = DefaultDstFileName
  629. End Sub
  630.  
  631. Private Sub txtDstModName_KeyPress(KeyAscii As Integer)
  632.     If KeyAscii = 13 Then
  633.         KeyAscii = 0
  634.         ' Update the same as if we've lost focus
  635.         txtDstModName_LostFocus
  636.     End If
  637. End Sub
  638.  
  639. Private Sub txtDstModName_LostFocus()
  640.     If txtDstModName = sEmpty Then txtDstModName = DefaultDstModName
  641.     UpdateTargetFileDisplay
  642. End Sub
  643.  
  644. Private Sub DisplayInvalid()
  645.     txtSrcModType = "Invalid Module"
  646.     chkDelegate = vbUnchecked
  647.     chkDelegate.Enabled = False
  648.     txtDst = sEmpty
  649.     txtDstFileName = sEmpty
  650.     txtDstFileName.Enabled = False
  651.     txtDstModName = sEmpty
  652.     txtDstModName.Enabled = False
  653.     txtDstModType = sEmpty
  654.     txtDeclFileName.Text = sEmpty
  655.     txtDeclFileName.Enabled = False
  656.     chkDeclView = vbUnchecked
  657.     chkDeclView.Enabled = False
  658.     cmdCreate.Enabled = False
  659. End Sub
  660.  
  661. Private Sub DisplayStandard()
  662.     txtSrcModType = "Standard Module"
  663.     chkDelegate = vbUnchecked
  664.     chkDelegate.Enabled = True
  665.     txtDstFileName = DefaultDstFileName
  666.     txtDstFileName.Enabled = True
  667.     txtDstModName = DefaultDstModName
  668.     txtDstModName.Enabled = True
  669.     txtDstModType = "Global Class"
  670.     txtDeclFileName.Text = "Objects.Bas"
  671.     txtDeclFileName.Enabled = True
  672.     chkDeclView = vbUnchecked
  673.     chkDeclView.Enabled = True
  674. End Sub
  675.  
  676. Private Sub DisplayPublic()
  677.     txtSrcModType = "Public Class"
  678.     chkDelegate = vbUnchecked
  679.     chkDelegate.Enabled = False
  680.     txtDstFileName = DefaultDstFileName
  681.     txtDstFileName.Enabled = True
  682.     txtDstModName = DefaultDstModName
  683.     txtDstModName.Enabled = True
  684.     txtDstModType = "Private Class"
  685.     txtDeclFileName.Text = "N/A"
  686.     txtDeclFileName.Enabled = False
  687.     chkDeclView = vbUnchecked
  688.     chkDeclView.Enabled = False
  689. End Sub
  690.  
  691. Private Sub DisplayGlobal()
  692.     txtSrcModType = "Global Class"
  693.     chkDelegate = vbUnchecked
  694.     chkDelegate.Enabled = False
  695.     txtDstFileName = DefaultDstFileName
  696.     txtDstFileName.Enabled = True
  697.     txtDstModName = DefaultDstModName
  698.     txtDstModName.Enabled = True
  699.     txtDstModType = "Standard Module"
  700.     txtDeclFileName.Text = "N/A"
  701.     txtDeclFileName.Enabled = False
  702.     chkDeclView = vbUnchecked
  703.     chkDeclView.Enabled = False
  704. End Sub
  705.  
  706. Private Sub DisplayPrivate()
  707.     txtSrcModType = "Private Class"
  708.     chkDelegate = vbUnchecked
  709.     chkDelegate.Enabled = False
  710.     txtDstFileName = DefaultDstFileName
  711.     txtDstFileName.Enabled = True
  712.     txtDstModName = DefaultDstModName
  713.     txtDstModName.Enabled = True
  714.     txtDstModType = "Public Class"
  715.     txtDeclFileName.Text = "N/A"
  716.     txtDeclFileName.Enabled = False
  717.     chkDeclView = vbUnchecked
  718.     chkDeclView.Enabled = False
  719. End Sub
  720.  
  721. Private Sub DisplayNothing()
  722.     txtSrc = sEmpty
  723.     txtSrcFileName = sEmpty
  724.     txtSrcModName = sEmpty
  725.     txtSrcModType = sEmpty
  726.     txtDst = sEmpty
  727.     chkDelegate = vbUnchecked
  728.     chkDelegate.Enabled = False
  729.     txtDstFileName = sEmpty
  730.     txtDstFileName.Enabled = False
  731.     txtDstModName = sEmpty
  732.     txtDstModName.Enabled = False
  733.     txtDstModType = sEmpty
  734.     txtDeclFileName = sEmpty
  735.     txtDeclFileName.Enabled = False
  736.     chkDeclView = vbUnchecked
  737.     chkDeclView.Enabled = False
  738.     cmdCreate.Enabled = False
  739. End Sub
  740.  
  741. Private Function DefaultDstFileName() As String
  742.     DefaultDstFileName = GetFileBase(sFileSrc)
  743.     Select Case emtCur
  744.     Case emtStandard
  745.         DefaultDstFileName = DefaultDstFileName & ".Cls"
  746.     Case emtClassGlobal
  747.         DefaultDstFileName = DefaultDstFileName & ".Bas"
  748.     Case emtClassPublic
  749.         DefaultDstFileName = "P_" & DefaultDstFileName & ".Cls"
  750.     Case emtClassPrivate
  751.         DefaultDstFileName = DefaultDstFileName & ".Cls"
  752.         If Left$(DefaultDstFileName, 2) = "P_" Then
  753.             DefaultDstFileName = Mid$(DefaultDstFileName, 3)
  754.         End If
  755.     End Select
  756. End Function
  757.  
  758. Private Function DefaultDstModName() As String
  759.     Select Case emtCur
  760.     Case emtStandard
  761.         If Left$(txtSrcModName, 1) = "M" Then
  762.             DefaultDstModName = "G" & Right$(txtSrcModName, Len(txtSrcModName) - 1)
  763.         Else
  764.             DefaultDstModName = "G" & txtSrcModName
  765.         End If
  766.     Case emtClassGlobal
  767.         If Left$(txtSrcModName, 1) = "G" Then
  768.             DefaultDstModName = "M" & Right$(txtSrcModName, Len(txtSrcModName) - 1)
  769.         Else
  770.             DefaultDstModName = "M" & txtSrcModName
  771.         End If
  772.     Case emtClassPublic
  773.         DefaultDstModName = txtSrcModName
  774.     Case emtClassPrivate
  775.         DefaultDstModName = txtSrcModName
  776.     End Select
  777. End Function
  778.  
  779. Private Function CreateBackupFile() As VbMsgBoxResult
  780.     Dim result As VbMsgBoxResult, sTemp As String
  781.     
  782.     result = MsgBox(sFileDst & " exists. Make backup? ", vbYesNoCancel, "Global Wizard")
  783.     If result = vbYes Then
  784.         sTemp = sFileDst
  785.         Mid$(sFileDst, Len(sFileDst)) = "K"
  786.         If ExistFile(sFileDst) Then Kill sFileDst
  787.         Name sTemp As sFileDst
  788.         sFileDst = sTemp
  789.     End If
  790.     CreateBackupFile = result
  791. End Function
  792.  
  793. Private Sub CreateDeclFile()
  794.     Dim sHeader As String
  795.     
  796.     ' Header for global objects declarations module
  797.     sHeader = "Attribute VB_Name = " & sQuote2 & "M" & GetFileBase(sFileDst) & sQuote2 & sCrLf & _
  798.               "Option Explicit" & sCrLf & sCrLf & _
  799.               "' Global Wizard-generated declarations. DO NOT EDIT THIS COMMENT!" & sCrLf
  800.  
  801.     SaveFileStr sFileDst, sHeader
  802. End Sub
  803.  
  804. Private Sub UpdateDeclFile()
  805.     On Error GoTo FileError
  806.     Dim sDeclaration As String, sComment As String
  807.     Dim sSrc As String, sDst As String, sLine As String
  808.     Dim iCommentStart As Long, iCommentEnd As Long
  809.     Dim iDeclStart As Long, iDeclEnd As Long
  810.     
  811.     ' Read in declarations file
  812.     sSrc = GetFileText(sFileDst)
  813.     
  814.     ' Look for Global Wizard comment
  815.     sComment = "' Global Wizard-generated declarations. DO NOT EDIT THIS COMMENT!"
  816.     iCommentStart = InStr(1, sSrc, sComment, vbTextCompare)
  817.     If iCommentStart = 0 Then
  818.         MsgBox "File " & sFileDst & _
  819.                " is not a Global Wizard-generated file. " & _
  820.                "Unable to update global object declarations.", vbOKOnly + vbExclamation, "Global Wizard"
  821.         Exit Sub
  822.     End If
  823.     iCommentEnd = iCommentStart + Len(sComment) + 1
  824.     
  825.     ' Look for previous declaration
  826.     sDeclaration = "Public " & txtSrcModName & " As New " & txtDstModName
  827.     iDeclStart = InStr(1, sSrc, sDeclaration, vbTextCompare)
  828.     If iDeclStart = 0 Then
  829.         ' No previous declaration. Insert in sorted order
  830.         sDst = Left$(sSrc, iCommentEnd)
  831.         sLine = GetNextLine(Mid$(sSrc, iCommentEnd + 1))
  832.         Do While (sLine <> sEmpty) And (UCase$(sDeclaration & sCrLf) > UCase$(sLine))
  833.             sDst = sDst & sLine
  834.             sLine = GetNextLine
  835.         Loop
  836.     
  837.         If sLine = sEmpty Then
  838.             ' Reached EOF. Insert new declaration at end
  839.             sDst = sDst & sDeclaration & sCrLf
  840.         Else
  841.             Dim iRemainder As Integer
  842.             iRemainder = Len(sSrc) - (Len(sDst) + Len(sLine))
  843.             ' Insert new declaration before current line
  844.             sDst = sDst & sDeclaration & sCrLf & sLine
  845.             ' Append the remaining declarations
  846.             sDst = sDst & Right$(sSrc, iRemainder)
  847.         End If
  848.     Else
  849.         ' Previous declaration. Replace with new one
  850.         sDst = sSrc
  851.         Mid$(sDst, iDeclStart, Len(sDeclaration)) = sDeclaration
  852.     End If
  853.     
  854.     SaveFileStr sFileDst, sDst
  855.     Exit Sub
  856.     
  857. FileError:
  858.     MsgBox Err.Description & sCrLf & sCrLf & _
  859.            "Unable to update global object declarations.", vbOKOnly + vbExclamation, "Global Wizard"
  860. End Sub
  861.  
  862.